
/*
 * Copyright (C) 2009 Archie L. Cobbs. All rights reserved.
 *
 * $Id: XMLByteArrayField.java 297 2010-01-13 21:22:19Z archie.cobbs $
 */

package org.dellroad.sidekar.xml;

/**
 * Container for a {@code byte[]}'s value during the Sidekar XML import/export process.
 */
class XMLByteArrayField extends XMLAtomicField<byte[]> {

    private byte[] value;
    private boolean isNull;

    // Used during unmarshalling
    private XMLByteArrayField(XMLItem xmlItem) {
        super(xmlItem);
    }

    // Used during unmarshalling
    private XMLByteArrayField(XMLField xmlField) {
        super(xmlField);
    }

    // Used during marshalling
    public XMLByteArrayField(String name, byte[] value) {
        super(name);
        this.value = value;
        this.isNull = value == null;
    }

    // Used during unmarshalling
    @Override
    public byte[] getObjectValue() {
        return this.isNull ? null : this.value;
    }

    // Used during unmarshalling
    public static XMLByteArrayField newInstance(Object obj) {
        return obj instanceof XMLItem ? new XMLByteArrayField((XMLItem)obj) : new XMLByteArrayField((XMLField)obj);
    }
}

